903A - Hungry Student Problem - CodeForces Solution


greedy implementation *900

Please click on ads to support us..

Python Code:

def get(x) -> str:
    if can_eat(x):
        return "YES"
    else:
        return "NO"


def can_eat(x: int) -> bool:
    if x == 0:
        return True
    if x < 3:
        return False
    if x in [3, 7]:
        return True

    if can_eat(x-3):
        return True
    if can_eat(x-7):
        return True

    return False


if __name__ == '__main__':
    n = int(input())

    for i in range(n):
        x = int(input())
        print(get(x))
		  					 	 	  			 	 	  		 	

C++ Code:

#include <bits/stdc++.h>
using namespace std;
int main(){
    int l[101];
    l[0] = 1;
    for(int i = 1; i < 101; i++){
        l[i] = 0;
        if(i - 3 >= 0) l[i] |= l[i - 3];
        if(i - 7 >= 0) l[i] |= l[i - 7];
    }
    int t;
    scanf("%d", &t);
    while(t--){
        int n;
        scanf("%d", &n);
        printf("%s\n", l[n] ? "YES" : "NO");
    }
}


Comments

Submit
0 Comments
More Questions

1436A - Reorder
1363C - Game On Leaves
1373C - Pluses and Minuses
1173B - Nauuo and Chess
318B - Strings of Power
1625A - Ancient Civilization
864A - Fair Game
1663B - Mike's Sequence
448A - Rewards
1622A - Construct a Rectangle
1620A - Equal or Not Equal
1517A - Sum of 2050
620A - Professor GukiZ's Robot
1342A - Road To Zero
1520A - Do Not Be Distracted
352A - Jeff and Digits
1327A - Sum of Odd Integers
1276A - As Simple as One and Two
812C - Sagheer and Nubian Market
272A - Dima and Friends
1352C - K-th Not Divisible by n
545C - Woodcutters
1528B - Kavi on Pairing Duty
339B - Xenia and Ringroad
189A - Cut Ribbon
1182A - Filling Shapes
82A - Double Cola
45A - Codecraft III
1242A - Tile Painting
1663E - Are You Safe